<?php

namespace V1;
class SF extends \ResourceClass
{
    public $isActive = true;
    public $remark = '顺丰物流通知';

    public function __construct()
    {
    }

    /*
     * 物流通知回调
     */
    public function post($postStr)
    {
        $data = array(
            'head' => array(
                'transType' => '4201',
                'transMessageId' => ''
            ),
            'body' => array(
                'orderId' => ''
            )
        );

        try{
            $postData = json_decode($postStr,true);
            if(isset($postData['body']['orderId']) && $postData['body']['orderId']){
                $orderId = $postData['body']['orderId'];
                $messageId = $postData['head']['transMessageId'];
                $mailNo = $postData['body']['mailNo'];

                $data['head']['transMessageId'] = $messageId;
                $data['body']['orderId'] = $orderId;
            }else{
                throw new \Exception('数据解析错误');
            }
            if($mailNo){
                //更新物流单号
                $invoiceInfo = \Biz\Invoice\Invoice::getByNumber($orderId);
                if($invoiceInfo['id']){
                    $rs = \Biz\Invoice\Invoice::update($invoiceInfo['id'],$invoiceInfo['number'],$invoiceInfo['purchase_id'],$invoiceInfo['purchase_number'],$invoiceInfo['logistics_id'],$mailNo,\Orm\Invoice\InvoiceClass::STATUS_YES);
                }
            }else{
                throw new \Exception('没有找到快递单号');
            }
        }catch (\Exception $e){
            printError(201,$e->getMessage());
        }
        return $data;
    }

}